﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using RBS.Common;
using RBS.Common.JsonEntity;
using RBS.Core.BLL;
using RBS.Web.Models;

namespace RBS.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index(/*string keyword = null*/)
        { 
             ViewData.Model = new RBS.Core.BLL.Sys_Links().GetModelList(" 1=1 order by sequence desc");  
            return View( );
        }

        [HttpPost]
        public JsonResult HotHotel(string category, int sort = 0, string cityName="")
        {
            Session["cityName"] = cityName;
            string where = string.Empty;
            where = "?city="+Session["cityName"]; ;
            where += "&type=0";
            where += "&category=" + category;
            where += "&sort=" + sort;
            where += "&limit=20";
            var jsonData = ApiRepository.Get("api/hotel/SelectHotel" + where);
           /* var serializer = new JavaScriptSerializer();
            ViewBag.JsonData = serializer.Serialize(jsonData);*/
            return Json(jsonData);
        } 

     /*   [HttpPost]
        public ActionResult Index(FormCollection formCollection)
        {
            string where = "?city=" + Session["cityName"];
            where += "&type=0";
            where += "&category=" + formCollection["category"];
            where += "&keyword=" + formCollection["keyword"];
            where += "&limit=20";
            /*   where += "&region=" + formCollection["region"];#1#
            where += "&sort=" + formCollection["sort"];
            var jsonData = ApiRepository.Get("api/hotel/SelectHotel" + where);
            var serializer = new JavaScriptSerializer();
            ViewBag.JsonData = serializer.Serialize(jsonData); 
            ViewBag.sort = formCollection["sort"];
            ViewBag.category = formCollection["category"];
            ViewBag.keyword = formCollection["keyword"];  
            return View();
        } */

        public ActionResult CityChange()
        { 
            return View();
        }
        public ActionResult SetCity(string cityName = null)
        {
            if (cityName != null)
            {
                Session["cityName"] = cityName;
            }
            return RedirectToAction("Index");
        }
       



        public ActionResult Apk()
        { 
            //将bitmap赋值给pictureBox以显示照片 
            return View();
        } 
        public ActionResult Error()
        {
            ViewBag.ErrorMsg = "非法操作！";
            return View();
        }  
        public ActionResult Ditu()
        {
            return View();
        }


        /// <summary>
        /// 获取酒店人均数
        /// </summary>
        /// <param name="hid"></param>
        /// <returns></returns>
        public JsonResult GetHotelRj(int hid)
        {
            var rj = new RBS.Core.BLL.Hotel.H_Hotels().GetRenJun(hid);
            return Json(rj,JsonRequestBehavior.AllowGet);
        }
    }

    
}
